//
//  SearchCollectionViewController.m
//  YSZC
//
//  Created by 张斌 on 16/4/13.
//  Copyright © 2016年 YueShiKeJi. All rights reserved.
//

#import "SearchCollectionViewController.h"
#import "YSDoViewManager.h"
#import "SearchCollectionViewCell.h"






#import "LoadVcManager.h"

@interface SearchCollectionViewController ()<UICollectionViewDelegateFlowLayout>
@property (weak, nonatomic) IBOutlet UITextField *searchbar;
@property (weak, nonatomic) IBOutlet UIView *titleview;

@property (weak, nonatomic) IBOutlet UICollectionViewFlowLayout *searchlayout;
@end

@implementation SearchCollectionViewController

static NSString * const reuseIdentifier = @"SearchCell";
- (IBAction)searchbtnclick:(id)sender {
    [self.navigationController pushViewController:[LoadVcManager sbVCWithsbname:@"WoyaogentouViewController"] animated:YES];
}

- (void)viewDidLoad {
    [super viewDidLoad];
    
    // Register cell classes
    [self.collectionView registerClass:[UICollectionViewCell class] forCellWithReuseIdentifier:reuseIdentifier];
    
    self.navigationItem.leftBarButtonItem = [[UIBarButtonItem alloc] initWithImage:[UIImage imageNamed:@"return"] style: UIBarButtonItemStylePlain target:self action:@selector(back)];
    
    self.searchlayout.itemSize =  CGSizeMake(([UIScreen mainScreen].bounds.size.width - 40*3)/2, ([UIScreen mainScreen].bounds.size.height- 4*40)/3);
    
//    self.searchlayout.minimumLineSpacing= 40 ;
    
//    self.searchlayout.minimumInteritemSpacing=0;
    
    self.searchlayout.scrollDirection=UICollectionViewScrollDirectionVertical;

    self.collectionView.delegate = self;
}

- (void)viewDidLayoutSubviews{
    [super viewDidLayoutSubviews];
    
    [[YSDoViewManager sharedmanager] settoyuanWithview:@[self.titleview]];
    
    
    
}
- (IBAction)search:(id)sender {
//    NSLog(@"搜索");
}
- (IBAction)close:(id)sender {
//    NSLog(@"关闭");
    self.searchbar.text = @"";
    [self.searchbar resignFirstResponder];
}

- (void)back{
    [self.navigationController popViewControllerAnimated:YES];
}

#pragma mark collectionview datasource

- (NSInteger)numberOfSectionsInCollectionView:(UICollectionView *)collectionView {
    
    return 1;
}


- (NSInteger)collectionView:(UICollectionView *)collectionView numberOfItemsInSection:(NSInteger)section {
    
    return 6;
}

- (UICollectionViewCell *)collectionView:(UICollectionView *)collectionView cellForItemAtIndexPath:(NSIndexPath *)indexPath {
    

    SearchCollectionViewCell *cell = [collectionView dequeueReusableCellWithReuseIdentifier:reuseIdentifier forIndexPath:indexPath];
    
    cell.backgroundColor=[UIColor colorWithRed:arc4random_uniform(256)/155.f green:arc4random_uniform(256)/155.f blue:arc4random_uniform(256)/155.f alpha:1];
    
    return cell;
    
}


#pragma mark collection delegate
- (UIEdgeInsets)collectionView:(UICollectionView *)collectionView layout:(UICollectionViewLayout*)collectionViewLayout insetForSectionAtIndex:(NSInteger)section{
    return UIEdgeInsetsMake(40, 40, 40, 40);
}

// 点击cell 的代理方法
- (void)collectionView:(UICollectionView *)collectionView didSelectItemAtIndexPath:(NSIndexPath *)indexPath{
    
    
    // 跳转到详情页面
   [ self.navigationController pushViewController:[LoadVcManager sbVCWithsbname:@"DetailViewController"] animated:YES];
}

// scrollview的代理方法
- (void)scrollViewDidScroll:(UIScrollView *)scrollView{
    [self.searchbar resignFirstResponder];
}


@end
